<?php

namespace App\Http\Service;

use App\Http\Util\Result;
use App\Model\PostCompany;

trait ServicePostCompany{

    /**
     * czs
     * @return mixed
     * 物流公司列表
     */
    public static function getList($keyWord,$limit){
        if (empty($keyWord)) {
            $list = PostCompany::orderBy('id','desc')->paginate($limit);
        } else {
            $list = PostCompany::orderBy('id','desc')->where("name","like", '%'.$keyWord.'%')->paginate($limit);
        }
        return Result::success()->setData($list);
    }

    /**
     *获取单个id记录
     * czs
     */
    public static function getOne($id) {
        $res = PostCompany::where("id", $id)->first();
        return Result::success()->setData($res);
    }

    /**
     *更新记录
     * czs
     */
    public static function updateData($input, $id) {
        $sel = PostCompany::where('id','<>',$id)->where('name',$input['name'])->count();
        if ($sel) {
            return Result::failure()->setMsg("公司名称请勿重复！");
        }
        $sel2 = PostCompany::where('id','<>',$id)->where('code',$input['code'])->count();
        if ($sel2) {
            return Result::failure()->setMsg("公司代码请勿重复！");
        }
        $res = PostCompany::where("id", $id)->update($input);
        return Result::success()->setData($res);
    }

    /**
     * czs
     *删除记录
     */
    public static function deleteLine($id) {
        $res = PostCompany::where("id", $id)->delete();
        return Result::success()->setData($res);
    }

    /**
     * 快递公司下拉
     * czs
     */
    public static function comPull() {
        $res = PostCompany::select('id', 'name')->get();
        return Result::success()->setData($res);
    }
}


